/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import entities.Franchise;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author Eduardo
 */

public class FranchiseDAO extends GeneralDAO {

    public Franchise searchById(EntityManager em,String id) {
        Query q = em.createQuery("SELECT f FROM Franchise AS f "
                + "  WHERE f.idFranchise = :id");
        q.setParameter("id", id);
        List<Franchise> results = q.getResultList();
        if (results == null) {
            return null;  // No encontrado
        } else {
            return results.get(0);  // Devuelve el encontrado
        }
    }
    
    public Franchise searchByName(EntityManager em,String name) {
        Query q = em.createQuery("SELECT f FROM Franchise AS f "
                + "  WHERE f.description = :parameter");
        q.setParameter("parameter", name);
        List<Franchise> results = q.getResultList();
        if (results == null) {
            return null;  // No encontrado
        } else {
            return results.get(0);  // Devuelve el encontrado
        }
    }


    public List<Franchise> searchAll(EntityManager em) {
        Query q = em.createQuery("SELECT f FROM franchise as f");
        return q.getResultList();
    }

}
